package com.hsource.doctorcenter.controller;

import com.hsource.common.utils.CommonResp;
import com.hsource.common.utils.resultUtils.controller.BaseController;
import com.hsource.doctorcenter.domain.order.Order;
import com.hsource.doctorcenter.service.api.IApiService;
import com.hsource.doctorcenter.service.order.IOrderService;
import com.hsource.doctorcenter.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @author yangYang
 * @version 1.0
 * @date 2020/9/28 14:47
 * @describe 订单控制层
 */
@Controller
@RequestMapping("/order")
public class OrderController extends BaseController {

    @Autowired
    private IApiService apiService;

    @Autowired
    private IOrderService orderService;



    /**
     * 回调订单
     * @param orderId 内部订单号
     * @return
     */
    @PostMapping("/callBackOrders")
    @ResponseBody
    public CommonResp callBackOrders(String orderId){
        Order order = orderService.selectOrderById(orderId);
        if(StringUtils.isNull(order)){
            return failed("未查询到订单信息");
        }
        if(order.getPayStatus().equals("D")){
            return success("订单付款成功");
        }

        return failed(1);
    }

    /**
     * 定向图文问题订单创建
     * @param order
     * @return
     */
    @PostMapping("/createOrientedProblemOrder")
    @ResponseBody
    public CommonResp createOrientedProblemOrder(Order order,String doctorIds){
        order.setOrderType("DirectedQuestions");
        Map<String, Object> map = orderService.redisOrder(order, doctorIds, "IT");
        return success(map);
    }
    /**
     * 定向电话问题订单创建
     * @param order
     * @return
     */
    @PostMapping("/createDirectedPhoneOrder")
    @ResponseBody
    public CommonResp createDirectedPhoneOrder(Order order,String doctorIds){
        order.setOrderType("DirectedPhone");
        Map<String, Object> map = orderService.redisOrder(order, doctorIds, "TH");
        return success(map);
    }
    /**
     * 快捷电话订单创建-订单缓存redis
     * @param order
     * @return
     */
    @PostMapping("/createQuickCallOrder")
    @ResponseBody
    public CommonResp createQuickCallOrder(Order order){
        order.setOrderType("QuickCall");
        Map<String, Object> map = orderService.redisOrder(order, "", "TH");
        return success(map);
    }

    /**
     * 图文急诊订单创建-订单缓存redis
     * @param order
     * @return
     */
    @PostMapping("/createImageTextOrder")
    @ResponseBody
    public CommonResp createImageTextOrder(Order order){
        order.setOrderType("ImageText");
        Map<String, Object> map = orderService.redisOrder(order, "", "IT");
        return success(map);
    }

    /**
     * 快速提问订单创建-订单缓存redis
     * @param order 订单信息
     * @return
     */
    @PostMapping("/createQuickQuestionsOrder")
    @ResponseBody
    public CommonResp createQuickQuestionsOrder(Order order,String doctorIds){
        order.setOrderType("QuickQuestions");
        Map<String, Object> map = orderService.redisOrder(order, doctorIds, "IT");
        return success(map);
    }


}
